package Pursuit_Client;

import java.io.*;
import java.util.Calendar;

//this class handles all logging done by PursuitClient

public class PursuitLog 
{
	String logName = "Pursuit.log";
	File log = new File(logName);
		
	public PursuitLog() 
		{}
	
	public void append(String entry) 
	{
		
		Calendar cal = Calendar.getInstance();	//pre-pend date to log entry
		String date = "[" + cal.get(Calendar.YEAR) + "/" + 
						(cal.get(Calendar.MONTH)+1) + "/" +
						cal.get(Calendar.DATE) + "] ";
		entry = date + entry;
		
    	try 
    	{
	        FileWriter fw = new FileWriter(logName, true);
	        fw.write(entry + '\n');//appends the string to the file
	        fw.close();
    	}
    	catch (IOException ioe) 
    	{	PursuitClient.print("Error in PursuitLog => log: " + ioe.getMessage());	}
	}
	
	public void clear() 
	{ //delete log
		log.delete();
	}
}
